package cn.niit.letuseatdemo.service.impl;

import cn.niit.letuseatdemo.entity.domain.SysUser;
import cn.niit.letuseatdemo.entity.domain.User;
import cn.niit.letuseatdemo.entity.domain.UserAddress;
import cn.niit.letuseatdemo.mapper.UserAddressMapper;
import cn.niit.letuseatdemo.service.UserAddressService;
import cn.niit.letuseatdemo.util.H5LoginUtil;
import cn.niit.letuseatdemo.util.LoginUserUtil;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;


/**
 * 用户地址Service业务层处理
 * 
 * @author aoli_jojo
 * @date 2022-10-26
 */
@Service
public class UserAddressServiceImpl implements UserAddressService
{
    @Autowired
    private UserAddressMapper userAddressMapper;

    /**
     * 查询用户地址
     * @Author: Zhang Shiqi
     * @param addressId 用户地址主键
     * @return 用户地址
     */
    @Override
    public UserAddress selectUserAddressByDId(Long addressId,Long userId)
    {
        return userAddressMapper.selectUserAddressByDId(addressId);
    }

    /**
     * 查询用户地址列表
     * @Author: Zhang Shiqi
     * @param userAddress 用户地址
     * @return 用户地址
     */
    @Override
    public List<UserAddress> selectUserAddressList(UserAddress userAddress,Long userId)
    {
        return userAddressMapper.selectUserAddressList(userId);

    }

    /*
    * @Description: 查询默认地址
    * @Author: Zhang Shiqi
    * @CreateTime： 2023/4/24 2:02
     * @param: userId
     * @return: cn.niit.letuseatdemo.entity.domain.UserAddress
    **/
    @Override
    public UserAddress selectUserDefualtAddress(Long userId) {
        UserAddress userAddress =userAddressMapper.selectUserDefualtAddress(userId);
        //System.out.println("服务接口的默认地址："+userAddress);
        return userAddress;
    }

    /**
     * 新增用户地址
     * @Author: Zhang Shiqi
     * @param userAddress 用户地址
     * @return 结果
     */
    @Override
    public int insertUserAddress(UserAddress userAddress)
    {
        return userAddressMapper.insertUserAddress(userAddress);
    }

    /**
     * 修改用户地址
     * 
     * @param userAddress 用户地址
     * @return 结果
     */
    @Override
    public int updateUserAddress(UserAddress userAddress)
    {
        User user = H5LoginUtil.getLoginUser();
        userAddress.setUserId(user.getUserId());
        userAddress.setUpdateUserId(user.getUserId());
        userAddress.setUpdateUserName(user.getUserName());
        userAddress.setGmtUpdate(new Date());
        return userAddressMapper.updateUserAddress(userAddress);
    }

    /*
    * @Description: 删除
    * @Author: Zhang Shiqi
    * @CreateTime： 2022/11/1 13:15
     * @param: addressId
     * @return: int
    **/
    @Override
    public int deleteUserAddressByAddressId(Long addressId) {
        return userAddressMapper.deleteUserAddressByAddressId(addressId);
    }

    /*
    * @Description: 根据地址id查地址
    * @Author: Zhang Shiqi
    * @CreateTime： 2023/4/25 4:17
     * @param: addressId
     * @return: cn.niit.letuseatdemo.entity.domain.UserAddress
    **/
    @Override
    public UserAddress selectUserAddressByAddressId(Long addressId) {
        return userAddressMapper.selectUserAddressByAddressId(addressId);
    }


}
